package com.ld.service;


import com.ld.task.AsyncTask;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

@Service(version = "1.0.0")
public class DubboTestServiceImpl implements DubboTestService {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private AsyncTask asyncTask;

    @Override
    public String aa(String name) {
        try {
            URI uri = new URI("https://www.cnblogs.com/coderjinjian/ajax/GetViewCount.aspx?postId=9644923");
            ResponseEntity<String> responseEntity = restTemplate.getForEntity(uri,String.class);
            System.out.println(responseEntity.getBody());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        return name;
    }

    @Override
    public String executorTest() {
        System.out.println("executorTest start");
        try {
            Future<String> result = asyncTask.doTask1();
            System.out.println(result.get());
            asyncTask.doTask2();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("executorTest end");
        return "null";
    }
}
